package com.aaa.mrcai.service.impl;

import com.aaa.mrcai.mapper.PasswordMapper;
import com.aaa.mrcai.pojo.entity.UserInfo;
import com.aaa.mrcai.pojo.entity.UserLogin;
import com.aaa.mrcai.pojo.vo.PasswordVO;
import com.aaa.mrcai.result.AjaxResult;
import com.aaa.mrcai.service.PasswordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletContext;


/**
 * @author meowyf
 * @version 1.0
 * @Name Z_MJ
 * @date 2021/12/11 15:23:18
 */
@Service
public class PasswordImpl implements PasswordService {
    @Autowired
    private PasswordMapper passwordMapper;
    @Autowired
    private ServletContext servletContext;

    @Override
    public AjaxResult list(int uid) {

        UserLogin i = passwordMapper.list(uid);
        String password = i.getPassword();
        servletContext.setAttribute("sss",password);
        System.out.println("2222222222222222222"+password);
        System.out.println("wqeeqwqwqwqw"+i);
        return null;
    }

    @Override
    public AjaxResult updatePassword(PasswordVO passwordVO) {
        System.out.println(passwordVO);
        if (!passwordVO.getOldPassword().equals(servletContext.getAttribute("sss"))){
            return AjaxResult.defeated();
        }
        UserInfo user = (UserInfo) servletContext.getAttribute("user");
        System.out.println(user);
        Integer id = user.getId();
        System.out.println(id);
        passwordVO.setId(id);
        int w = passwordMapper.updatePassword(passwordVO);
        System.out.println("oooooooooooooooooooo"+w);
        if (w>0){
            return AjaxResult.success();
        }
        return AjaxResult.defeated();

    }

    @Override
    public void logout() {

    }
}
